# -*- coding:utf-8 -*-
from xiamiulike import *
import unittest

class TestULike(unittest.TestCase):
    def testMidLike(self):
        """
        get uid and like score from one unit
        """
        thestr = """
<tr class="" id="lib_song_384570" title="">
	<td class="chkbox"><input type="checkbox" name="recommendids" value="384570" checked="checked"></td>
	<td class="song_name"><a title="Shall We Talk" href="/song/384570">Shall We Talk</a> - 
		<a class="artist_name" href="/artist/135" title="陈奕迅">陈奕迅</a>
		</td>
		<td class="song_rank"><p class="grade"><input type="hidden" name="grade" value="5"><a href="javascript:;" title="" class="selected"></a><a href="javascript:;" title="" class="selected"></a><a href="javascript:;" title="" class="selected"></a><a href="javascript:;" title="" class="selected"></a><a href="javascript:;" title="" class="selected"></a> </p></td>
		<td class="song_act"><div class="song_do" style="width:170px;"><a onclick="play('384570');" title="Shall We Talk在线试听" href="javascript:void(0)" class="song_play">小情歌在线试听</a> <a onclick="recommend(384570,'32');" title="推荐给好友" href="javascript:void(0)" class="song_digg">Shall We Talk推荐</a> <a onclick="collect('384570');" title="添加Shall We Talk到精选集" href="javascript:void(0)" class="song_toclt">添加到</a> <a onclick="xm_download('384570');" title="Shall We Talk下载" href="javascript:void(0)" class="song_download">Shall We Talk下载</a>
	<a class="song_tel" href="javascript:void(0)" onclick="showDialog('/music/send/id/384570');" title="发送到我的设备">发送到我的设备</a>
	<div class="song_menu"><a title="更多" href="javascript:void(0)" class="song_more">更多</a><span class="song_menu_drop"><em></em>	<!--<a title="" href="/widget/isingle?sid=384570" class="toplayer">转贴到其它网站</a>-->
	

			<a href="javascript:;return;" onclick="getquote(3,'384570')" style="border-bottom: 1px #D8D8D8 solid;" class="toplayer" title="转贴到其他网站">转贴到其他网站</a>

	</span></div>
	</div></td>
	<td class="private_act">
			</td>
	
</tr>"""
        mid,grade =  getMidGrade(thestr)
        self.assertEqual(mid,384570)
        self.assertEqual(grade,5)

    def testCrawl(self):
        """
        this test is not that good
        """
        uid = 1
        midGradeL = getULike(uid)
        midL = [mid for mid,grade in midGradeL]
        gradeL = [grade for mid,grade in midGradeL]
        check1 =  midL.count(390829)
        self.assertEqual(check1,1)


if __name__ == "__main__":
    unittest.main()
